Skip to content

fix(agentchat): validate participants type in BaseGroupChat with clear TypeError - #7646

Closed
xodn348 wants to merge 1 commit into
microsoft:mainfrom
xodn348:fix/roundrobin-participants-validation
Closed

fix(agentchat): validate participants type in BaseGroupChat with clear TypeError#7646
xodn348 wants to merge 1 commit into
microsoft:mainfrom
xodn348:fix/roundrobin-participants-validation

Conversation

@xodn348

@xodn348 xodn348 commented Apr 30, 2026

Copy link
Copy Markdown

Summary

Fixes #7580

When a user accidentally passes None, a non-list value (e.g. a string or integer), or a list containing non-agent/non-team objects as participants to RoundRobinGroupChat (or any BaseGroupChat subclass), the current code raises low-level internal errors that are hard to debug:

  • TypeError: object of type 'NoneType' has no len() — for participants=None
  • AttributeError: 'str' object has no attribute 'name' — for participants="not a list" or a list containing a string

Changes

  • _base_group_chat.py: Added explicit type validation at the top of BaseGroupChat.__init__ — checks that participants is a list and that every element is a ChatAgent or Team instance, raising a descriptive TypeError before any internal logic runs.
  • _round_robin_group_chat.py: Updated the Raises docstring to document the new TypeError.
  • tests/test_group_chat.py: Added test_group_chat_invalid_participants — a synchronous test covering all four bad-input cases: None, a string, an integer, and a list containing a non-agent item.

Before / After

# Before (confusing internal error)
RoundRobinGroupChat(participants=None)
# TypeError: object of type 'NoneType' has no len()

# After (clear, actionable message)
RoundRobinGroupChat(participants=None)
# TypeError: participants must be a list of ChatAgent or Team instances, got 'NoneType'.

# Before
RoundRobinGroupChat(participants=[agent, "bad"])
# AttributeError: 'str' object has no attribute 'name'

# After
RoundRobinGroupChat(participants=[agent, "bad"])
# TypeError: participants[1] must be a ChatAgent or Team instance, got 'str'.

The fix is in BaseGroupChat, so it covers all subclasses (RoundRobinGroupChat, SelectorGroupChat, Swarm, MagenticOneGroupChat) automatically.

…r TypeError

Before this change, passing None, a string, or a list containing
non-agent objects to RoundRobinGroupChat (and other group chat types)
raised low-level internal errors such as:
  - TypeError: object of type 'NoneType' has no len()
  - AttributeError: 'str' object has no attribute 'name'

Now BaseGroupChat.__init__ validates that participants is a list and
that each element is a ChatAgent or Team instance, raising a descriptive
TypeError before any internal code runs.

Fixes #7580
@xodn348 xodn348 closed this by deleting the head repository Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RoundRobinGroupChat raises raw AttributeError/TypeError for invalid participants instead of a clear validation error

1 participant